package com.com.hefei.wdp.example;

import com.netflix.hystrix.HystrixMetrics;
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
//@EnableDiscoveryClient 用户获取Eureka服务器上注册的服务的基本信息，
//在contorller中注入DiscoveryClient discoveryClient来获取注册的服务信息
@EnableDiscoveryClient
@EnableEurekaClient //eureka客户端
@SpringBootApplication
@EnableCircuitBreaker //Hystrix注解
public class ProducerRibbonApplication {
    public static void main(String[] args) {
        SpringApplication.run(ProducerRibbonApplication.class, args);
    }

    /**
     * 此配置是为了服务监控而配置，与服务容错本身无关，springcloud 升级后的坑
     * ServletRegistrationBean 因为spring boot 的默认路径不是"/hystrix.stream"
     * 只要是在机子的项目里配置上下面的servlet 就可以了
     * @return
     */
    public ServletRegistrationBean getServlet(){
        HystrixMetricsStreamServlet streamServlet =new HystrixMetricsStreamServlet();
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/hystrix.stream");
        registrationBean.setName("HystrixMetricsStreamServlet");
        return registrationBean;
    }
}
